<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:h="livcos.org/ns/cosmos/history"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="xs c h f">
  
  <xsl:import href="../style/base.xsl"/>
  <xsl:import href="../style/view.xsl"/>
  <xsl:import href="../style/web.xsl"/>
  
  <xsl:param name="view"/>
  <xsl:variable name="scope" select="'history'"/>
  
  <xsl:template match="/*">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link href="{$toDomainPath}/web/css/styles.css" rel="stylesheet" type="text/css"/>
        <link href="./css/ext-all.css" rel="stylesheet" type="text/css"/>
        <link href="./css/history.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="./script/ext/ext-base.js"><!-- --></script>
        <script type="text/javascript" src="./script/ext/ext-all-debug.js"><!-- --></script>
        <script type="text/javascript" src="./script/history.js"><!-- --></script>
        <script>
          <xsl:choose>
          <xsl:when test="$view">
            var viewLink = "<xsl:value-of select="$view"/>";
          </xsl:when>
          <xsl:otherwise>
            var viewLink = "../../../livcos.org/web/data?ref=<xsl:value-of select="$ref"/>";
          </xsl:otherwise>
        </xsl:choose>
        </script>
      </head>
      <body>
        <div id="header" class="x-panel-header">
          <span style="font-variant: small-caps;">History of </span>
          <xsl:value-of select="$absRef"/>
        </div>
        <div id="_history1">
          <script>
            var store1 = new Ext.data.SimpleStore({
              fields: [
                {name: 'id'},
                {name: 'time'}
              ],
              data: [
                <xsl:apply-templates select="h:change">
                  <xsl:sort select="@time" order="descending"/>
                </xsl:apply-templates>
              ]
            });
          </script>
        </div>
        <div id="_history1">
          <script>
            var store2 = new Ext.data.SimpleStore({
              fields: [
                {name: 'id'},
                {name: 'time'}
              ],
              data: [
                <xsl:apply-templates select="h:change">
                  <xsl:sort select="@time" order="descending"/>
                </xsl:apply-templates>
              ]
            });
          </script>
        </div>
        <div id="_preview1">
          <iframe id="preview1" name="preview1" marginwidth="0" marginheight="0" vspace="0" hspace="0"
            frameborder="0"/>
        </div>
        <div id="_preview2">
          <iframe id="preview2" name="preview2" marginwidth="0" marginheight="0" vspace="0" hspace="0"
            frameborder="0"/>
        </div>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="@time">
    <xsl:value-of select="format-dateTime(xs:dateTime(.), '[Y0001]-[M01]-[D01]&#160;[H01]:[m01]:[s01]')"/>
  </xsl:template>
  
  <xsl:template match="h:*">
    <xsl:if test="position() > 1">,</xsl:if>
    <xsl:text>['</xsl:text>
    <xsl:value-of select="@id"/>
    <xsl:text>','</xsl:text>
    <xsl:apply-templates select="@time"/>
    <xsl:text>']</xsl:text>
  </xsl:template>
  
</xsl:stylesheet>